######################################
# version : debugman007/centos-ssh:1.0
# centos : 7
# desc : centos上安装的ssh
######################################
FROM centos:7

# 下面是一些创建者的基本信息
MAINTAINER azshara "limitshel@live.com"

# 安装openssh和sudo软件包，并且将sshd的UsePAM参数设置成no  
RUN yum install -y openssh-server openssh-clients sudo which
COPY sshd_config /etc/ssh/

# 添加用户 hadoop，设置密码为 hadoop, 赋予sudo权限
RUN groupadd hadoop
RUN useradd -d /home/hadoop -m hadoop -g hadoop
RUN echo "hadoop:hadoop" | chpasswd
RUN echo "hadoop ALL= NOPASSWD: ALL" >> /etc/sudoers

#配置ssh
RUN echo "root:root" | chpasswd
RUN mkdir /var/run/sshd 
EXPOSE 22

USER hadoop
RUN ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
RUN cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
RUN chmod 700 ~/.ssh
RUN chmod 600 ~/.ssh/authorized_keys
 
USER root
RUN ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
RUN cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
RUN chmod 700 ~/.ssh
RUN chmod 600 ~/.ssh/authorized_keys

# 配置环境变量
ADD profile /etc/profile
RUN source /etc/profile

# 安装和配置 jdk
ADD jdk-8u152-linux-x64.tar.gz /software
RUN mv /software/jdk1.8.0_152 /software/jdk

WORKDIR /software
RUN rm -f jdk-8u152-linux-x64.tar.gz

# 创建 hadoop 数据目录
RUN mkdir -p /data/hadoop
WORKDIR /data/hadoop
RUN mkdir -p tmp hdfs/name hdfs/data hdfs/namesecondary

# 安装 hadoop
ADD hadoop-2.8.2.tar.gz /software
RUN rm -f /software/hadoop-2.8.2.tar.gz

# 配置 hadoop 
ADD hadoop-env.sh /software/hadoop-2.8.2/etc/hadoop/
ADD core-site.xml /software/hadoop-2.8.2/etc/hadoop/ 
ADD hdfs-site.xml /software/hadoop-2.8.2/etc/hadoop/
ADD mapred-site.xml /software/hadoop-2.8.2/etc/hadoop/
ADD yarn-site.xml /software/hadoop-2.8.2/etc/hadoop/ 
ADD masters /software/hadoop-2.8.2/etc/hadoop/
ADD slaves /software/hadoop-2.8.2/etc/hadoop/

# 安装和配置 hbase
ADD hbase-1.3.1-bin.tar.gz /software
RUN mkdir -p /software/hbase-1.3.1/tmp/zookeeper
RUN rm -f /software/hbase-1.3.1-bin.tar.gz

# 配置 hbase
ADD hbase-env.sh /software/hbase-1.3.1/conf/
ADD hbase-site.xml /software/hbase-1.3.1/conf/
ADD regionservers /software/hbase-1.3.1/conf/

# 配置 hadoop hbase 权限
RUN chown -R hadoop:hadoop /software/hadoop-2.8.2
RUN chown -R hadoop:hadoop /software/hbase-1.3.1
RUN chown -R hadoop:hadoop /data/hadoop

# 配置 host
ADD hosts.sh /home/hadoop/

CMD ["/usr/sbin/init"]
